package com.bawei.module_detail.model.repository

import com.bawei.lib_common.entity.SendCommentBody
import com.bawei.lib_net.RetrofitFactory
import com.bawei.module_detail.model.api.VideoDetailApi
import com.bawei.module_detail.model.entity.LikeCollectBody
import com.bawei.module_detail.model.entity.ReplyBody
import com.bawei.module_detail.model.entity.SendBulletBody
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

class VideoDetailRepository {
    val api: VideoDetailApi
    init {
        api= RetrofitFactory.getRetrofitFactory().create(VideoDetailApi::class.java)
    }
    /**
     * 推荐视频
     */
    fun getVideoRecommend(page:Int,pageSize:Int) = flow {
        emit(api.getVideoRecommend(page,pageSize))
    }.flowOn(Dispatchers.IO)
    /**
     * 视频评论
     */
    fun getCommentByUserId(datatype: Int, itemid: String) = flow {
        emit(api.getCommentByUserId(datatype,itemid))
    }.flowOn(Dispatchers.IO)
    /**
     * 发送评论
     */
    fun sendComment(body: SendCommentBody) = flow {
        emit(api.sendComment(body))
    }.flowOn(Dispatchers.IO)
    /**
     * 删除评论
     */
    fun deleteComment(commentid: Int) = flow {
        emit(api.deleteComment(commentid))
    }.flowOn(Dispatchers.IO)
    /**
     * 回复评论
     */
    fun reply(replyBody: ReplyBody) = flow {
        emit(api.reply(replyBody))
    }.flowOn(Dispatchers.IO)
    /**
     * 删除回复评论
     */
    fun replyDelete(id:Int) = flow {
        emit(api.replyDelete(id))
    }.flowOn(Dispatchers.IO)
    /**
     * 获取弹幕
     */
    fun getBullet(datatype:Int,itemid:String) = flow {
        emit(api.getBullet(datatype,itemid))
    }.flowOn(Dispatchers.IO)
    /**
     * 发送弹幕
     */
    fun sendBullet(body: SendBulletBody) = flow {
        emit(api.sendBullet(body))
    }.flowOn(Dispatchers.IO)
    /**
     * 点赞
     */
    fun agreeVideo(body: LikeCollectBody) = flow {
        emit(api.agreeVideo(body))
    }.flowOn(Dispatchers.IO)
    /**
     * 取消点赞
     */
    fun cancelAgreeVideo(body: LikeCollectBody) = flow {
        emit(api.cancelAgreeVideo(body))
    }.flowOn(Dispatchers.IO)
    /**
     * 检查是否点赞
     */
    fun checkAgreeVideo(sourceflag: String, userId: Int) = flow {
        emit(api.checkAgreeVideo(sourceflag,userId))
    }.flowOn(Dispatchers.IO)
    /**
     * 收藏
     */
    fun collectVideo(body: LikeCollectBody) = flow {
        emit(api.collectVideo(body))
    }.flowOn(Dispatchers.IO)
    /**
     * 取消收藏
     */
    fun cancelCollectVideo(body: LikeCollectBody) = flow {
        emit(api.cancelCollectVideo(body))
    }.flowOn(Dispatchers.IO)
    /**
     * 检查收藏是否收藏
     */
    fun checkCollectVideo(sourceflag: String, userId: Int) = flow {
        emit(api.checkCollectVideo(sourceflag,userId))
    }.flowOn(Dispatchers.IO)
}